import pandas as pd
from sklearn.impute import KNNImputer
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.metrics.pairwise import euclidean_distances
df = pd.read_csv("D:\数据挖掘\数据预处理-两次实验\数据预处理-实验1\house_train.csv", usecols=['id','distirct','built_date','green_rate','area','oriented','traffic','shockproof','school','crime_rate','pm25','price'])

#KNN imputation补齐缺失值
imp_KNN = KNNImputer(n_neighbors=2)
imp_KNN=imp_KNN.fit(df)
X2=imp_KNN.transform(df)

#采用欧几里得距离计算任意两个样本之间的距离
Euclidean=euclidean_distances(X2,X2)
print("欧几里得距离为:\n",Euclidean)

#采用余弦相似度计算任意两个样本之间的相似度
Cosine =cosine_similarity(X2,X2)
print("余弦相似度为:\n",Cosine)